package system;

import java.util.ArrayList;

public class TextDirector {
	//TextHandler[] damages;
	ArrayList<TextHandler> handlers;

	int index, max;

	public TextDirector(){
		index = 0;
		max = 50;
		//damages = new TextHandler[max];
		handlers = new ArrayList<TextHandler>();
	}

	// NOTE: updated to round-robin queue. win or lag?
	public void add(String text, String filename, int x, int y, int splash){
		TextHandler t = new TextHandler(x, y, filename, 30, splash, true);
		t.setText(text);
		
		handlers.add(t);
		//index = (index + 1)%max;

	}
	
	public void add(int number, String filename, int x, int y, int splash){
		this.add(Integer.toString(number), filename, x, y, splash);
	}

	public void update() {

		for(int i = 0; i < handlers.size(); i++){
			if (handlers.get(i)!= null){
				if (handlers.get(i).totalDuration > 0){
					if(handlers.get(i).splash !=0){
						handlers.get(i).yvel += 1.2;		// gravity
					}
					//damages.get(i).
					handlers.get(i).update();

				}
			}
			
			if (handlers.get(i).curDuration > handlers.get(i).totalDuration){
				handlers.remove(i);
			}
		}

	}
	
	public TextHandler getHandler(int index){
		return handlers.get(index);
	}
	
	public int getIndex(){
		return index;
	}

	public int getLength() {
		return handlers.size();
	}
	
	public boolean isEmpty(){
		return (handlers.size() == 0);
	}
}

